//
//  ZYCAttendanceRecordMenuView.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/11.
//

#import "ZYCAttendanceRecordMenuView.h"
#import "MenuButton.h"

@interface ZYCAttendanceRecordMenuView ()

@property (nonatomic, strong) MenuButton *leftButton;
@property (nonatomic, strong) MenuButton *middleButton;
@property (nonatomic, strong) MenuButton *rightButton;
@property (nonatomic, strong) UIView *lineOne;
@property (nonatomic, strong) UIView *lineTwo;

@end
@implementation ZYCAttendanceRecordMenuView

- (void)setLeftStr:(NSString *)leftStr{
    _leftStr = leftStr;
    [_leftButton setTitle:leftStr forState:UIControlStateNormal];
}
- (void)setRightStr:(NSString *)rightStr{
    _rightStr = rightStr;
    [_rightButton setTitle:rightStr forState:UIControlStateNormal];
}

- (void)setMiddleStr:(NSString *)middleStr{
    _middleStr = middleStr;
    [_middleButton setTitle:middleStr forState:UIControlStateNormal];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self addSubview:self.leftButton];
        [self addSubview:self.middleButton];
        [self addSubview:self.rightButton];
        [self addSubview:self.lineOne];
        [self addSubview:self.lineTwo];
        
        [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(self.bounds.size.width / 3, 46));
            make.left.equalTo(self);
        }];

        [self.middleButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(self.bounds.size.width / 3, 46));
            make.left.equalTo(self.leftButton.mas_right);
        }];
        
        [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(self.bounds.size.width / 3, 46));
            make.right.equalTo(self);
        }];
        
        [self.lineOne mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_left).offset(self.bounds.size.width / 3);
            make.top.equalTo(self).offset(12.0f);
            make.bottom.equalTo(self).offset(-12.0f);
            make.width.mas_equalTo(1);
        }];
        
        [self.lineTwo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.mas_left).offset(self.bounds.size.width / 3 * 2);
            make.top.equalTo(self).offset(12.0f);
            make.bottom.equalTo(self).offset(-12.0f);
            make.width.mas_equalTo(1);
        }];
        

    }
    return self;
}
- (MenuButton *)leftButton {
    if (!_leftButton) {
        _leftButton = [MenuButton buttonWithType:UIButtonTypeCustom];
        _leftButton.titleLabel.font = kCustomFont(@"PingFangSC-Regular", 15.0f);;
        [_leftButton setTitleColor:HEX_RGB(@"#2B302D") forState:UIControlStateNormal];
        _leftButton.tag = 1000;
        [_leftButton setImage:[UIImage imageNamed:@"arrow_down"] forState:UIControlStateNormal];
        [_leftButton addTarget:self action:@selector(clickBtnAction:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _leftButton;
}

- (MenuButton *)middleButton {
    if (!_middleButton) {
        _middleButton = [MenuButton buttonWithType:UIButtonTypeCustom];
        _middleButton.titleLabel.font = kCustomFont(@"PingFangSC-Regular", 15.0f);;
        [_middleButton setTitleColor:HEX_RGB(@"#2B302D") forState:UIControlStateNormal];
        _middleButton.tag = 1001;
        [_middleButton setImage:[UIImage imageNamed:@"arrow_down"] forState:UIControlStateNormal];
        [_middleButton addTarget:self action:@selector(clickBtnAction:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _middleButton;
}


- (MenuButton *)rightButton {
    if (!_rightButton) {
        _rightButton =  [MenuButton buttonWithType:UIButtonTypeCustom];
        _rightButton.titleLabel.font = kCustomFont(@"PingFangSC-Regular", 15.0f);
        _rightButton.tag = 1002;
        [_rightButton setTitleColor:HEX_RGB(@"#2B302D") forState:UIControlStateNormal];
        [_rightButton setImage:[UIImage imageNamed:@"arrow_down"] forState:UIControlStateNormal];
        [_rightButton addTarget:self action:@selector(clickBtnAction:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _rightButton;
}


- (UIView *)lineOne {
    if (!_lineOne) {
        _lineOne = [[UIView alloc] init];
        _lineOne.backgroundColor = HEX_RGB(@"#EFEFEF");
    }
    return _lineOne;
}

- (UIView *)lineTwo {
    if (!_lineTwo) {
        _lineTwo = [[UIView alloc] init];
        _lineTwo.backgroundColor = HEX_RGB(@"#EFEFEF");
    }
    return _lineTwo;
}


- (void)clickBtnAction:(UIButton *)sender{
    
    if (sender.tag == 1000) {
        if ([self.delegate respondsToSelector:@selector(attendanceRecordMenuViewClickLeft)]) {
            [self.delegate attendanceRecordMenuViewClickLeft];
        }
        
    }else if(sender.tag == 1001){
        if ([self.delegate respondsToSelector:@selector(attendanceRecordMenuViewClickMiddle)]) {
            [self.delegate attendanceRecordMenuViewClickMiddle];
        }
    }else if(sender.tag == 1002){
        if ([self.delegate respondsToSelector:@selector(attendanceRecordMenuViewClickRight)]) {
            [self.delegate attendanceRecordMenuViewClickRight];
        }
    }
    
}


@end
